﻿namespace AspDotNet.Core7.First.Middlewares
{
    public partial class ContentMiddleware
    {
        public class ShortCircuitMiddleware : BaseMiddleware
        {
            public ShortCircuitMiddleware(RequestDelegate nextMiddleware)
                : base(nextMiddleware)
            {
            }

            public override async Task Invoke(HttpContext httpContext)
            {
                //if (httpContext.Request.Headers["User-Agent"].Any(v => v.Contains("Firefox")))
                if (httpContext.Items["Firefox"] as bool? == true)
                {
                    httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
                }
                else
                {
                    await NextMiddleware.Invoke(httpContext);
                }
            }
        }
    }
}
